package com.yanqu.road.logic.activity;

import com.yanqu.road.entity.activity.douluodalu.DouLuoDaLuPatronsBattle;
import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuConfig;
import com.yanqu.road.entity.activity.douluodalu.enums.eDouLuoDaLuBuffType;
import com.yanqu.road.entity.activity.douluodalu.result.BuffCalResult;

import java.math.BigDecimal;

public class DouLuoDaLuLogic {

    /**
     * 计算对决购买buff的加成
     */
    public static BuffCalResult battleBuyBuff(DouLuoDaLuConfig config, int buyBuffIdx, DouLuoDaLuPatronsBattle patronsBattle, boolean firstBuy){
        int buff;
        long buffAddition;
        if(firstBuy){
            buff = config.FIGHT_BUFF_FIRSTADD.get(buyBuffIdx - 1);
        }else {
            buff = config.FIGHT_BUFF_ADD.get(buyBuffIdx - 1);
        }
        buffAddition = BigDecimal.valueOf(patronsBattle.getHunLi()).multiply(BigDecimal.valueOf(buff))
                .divide(BigDecimal.valueOf(100l), 0, BigDecimal.ROUND_UP).longValue();
        patronsBattle.setBlood(patronsBattle.getBlood() + buffAddition);
        patronsBattle.setTotalBlood(patronsBattle.getTotalBlood() + buffAddition);
        return new BuffCalResult(buff, buffAddition);
    }

    /**
     * 计算仙草buff加成
     */
    public static long calBuff(long src, eDouLuoDaLuBuffType buffType, DouLuoDaLuConfig config){
        if(config == null){
            return src;
        }
        if(buffType.getType() == 1){
            return BigDecimal.valueOf(src).multiply(BigDecimal.valueOf(100l + config.getXianCaoBuffAddition(buffType)))
                    .divide(BigDecimal.valueOf(100), 0, BigDecimal.ROUND_UP).longValue();
        }else if(buffType.getType() == 2){
            return src + config.getXianCaoBuffAddition(buffType);
        }
        return src;
    }

}
